<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>
        <ui:composition template="./../../WEB-INF/templates/noFooterTemplate.xhtml">
            <ui:define name="content">
                <h:form id="publicRelationsEditForm">
                    <p:dialog modal="true" style="width:250px;" header="#{messages.EditProfile}" resizable="false" id="editProfileDialog" widgetVar="editProfileDialog" rendered="true" draggable="true" closable="true"> 
                        <p:panel styleClass="noMargin noPadding noBorder" id="publicRelationsEditPanel">
                            <p:panel styleClass="noBorder" rendered="#{adminPublicRelationshipsBean.chosenEntity!=null}">
                                <h:panelGrid  styleClass="noBorderSpacing" columns="2">  
                                    <p:outputLabel for="name" value="#{messages.Name}" />
                                    <p:inputText id="name" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.name}"  requiredMessage="#{messages.NameRequired}" label="#{messages.Name}">  
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>  
                                    <p:outputLabel for="name" value="#{messages.LastName}" />
                                    <p:inputText id="lastName" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.lastName}"  requiredMessage="#{messages.LastNameRequired}" label="#{messages.LastName}">
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>
                                    <p:outputLabel for="name" value="#{messages.Dni}" />
                                    <p:inputText id="dni" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.dni}"  requiredMessage="#{messages.DniRequired}" label="#{messages.Dni}">
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>
                                    <p:outputLabel for="name" value="#{messages.Phone}" />
                                    <p:inputText id="phone" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.phone}"  requiredMessage="#{messages.PhoneRequired}" label="#{messages.Phone}">
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>
                                    <p:outputLabel for="name" value="#{messages.Email}" />
                                    <p:inputText id="email" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.user.email}"  requiredMessage="#{messages.EmailRequired}" label="#{messages.Email}">
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>
                                    <p:outputLabel for="name" value="#{messages.PayPerCandidate}" />
                                    <p:inputText id="payPerCandidate" required="true" value="#{adminPublicRelationshipsBean.chosenEntity.payPerCandidate}"  requiredMessage="#{messages.PayPerCandidateRequired}" label="#{messages.PayPerCandidate}">
                                        <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:inputText>
                                    <p:outputLabel for="name" value="#{messages.Active}" />
                                    <p:selectOneMenu id="selectActive" value="#{adminPublicRelationshipsBean.chosenEntity.user.active}" effect="fade" required="false" label="#{messages.Active}" requiredMessage="#{messages.Active}">  
                                        <f:selectItem itemLabel="#{messages.Active}" itemValue="" />
                                        <f:selectItem itemLabel="#{messages.Yes}" itemValue="#{true}" />
                                        <f:selectItem itemLabel="#{messages.No}" itemValue="#{false}" />
                                        <p:ajax event="change" process="@this" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                    </p:selectOneMenu>
                                </h:panelGrid>
                                <p:commandButton id="saveProfileButton"  value="#{messages.Edit}" update=":adminPublicRelationshipsForm:publicRelationsDataTable editProfileDialog" actionListener="#{adminPublicRelationshipsBean.editProfile()}"/>
                            </p:panel>
                        </p:panel>
                    </p:dialog>
                </h:form>

                <h:form id="newPublicRelationshipsDialogForm">                   
                    <p:dialog id="newPublicRelationshipsDialog" widgetVar="newPublicRelationshipsDialog">
                        <p:panel id="newPublicRelationshipsDialogPanel">
                            <p:panelGrid columns="2">
                                <h:outputText value="#{messages.Name}" />
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.name}" required="true" />
                                <h:outputText value="#{messages.LastName}" />
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.lastName}" required="true"/>
                                <h:outputText value="#{messages.Dni}" />
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.dni}" required="true"/>
                                <h:outputText value="#{messages.Email}" />
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.user.email}" required="true">
                                    <f:validator  binding="#{emailValidator}"></f:validator>
                                    <p:ajax event="change" update=":adminPublicRelationshipsForm:preferencesGrowl" />
                                </p:inputText> 
                                <h:outputText value="#{messages.Password}" />
                                <p:password styleClass="loginInput" id="password" match="password2" feedback="true" value="#{adminNewPublicRelationsBean.publicRelationship.user.password}" required="true" requiredMessage="#{messages.PasswordRequired}" label="#{messages.Password}">
                                    <f:validateLength minimum="5" maximum="30"></f:validateLength>
                                </p:password>
                                <h:outputText value="#{messages.RepeatPassword}" />
                                <p:password styleClass="loginInput" id="password2" feedback="true" value="#{adminNewPublicRelationsBean.publicRelationship.user.password}" required="true" requiredMessage="#{messages.RepeatPasswordRequired}" label="#{messages.RepeatPassword}">
                                </p:password>
                                <h:outputText value="#{messages.Phone}" />  
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.phone}" required="true"/>
                                <h:outputText value="#{messages.PayPerCandidate}" /> 
                                <p:inputText value="#{adminNewPublicRelationsBean.publicRelationship.payPerCandidate}" />
                            </p:panelGrid>
                        </p:panel>
                        <p:commandButton value="#{messages.Save}" update="newPublicRelationshipsDialogPanel :adminPublicRelationshipsForm:publicRelationsDataTable :adminPublicRelationshipsForm:preferencesGrowl"  id="newPublicRelationshipsButtonSave" actionListener="#{adminNewPublicRelationsBean.createPublicRelationships()}" onsuccess="newPublicRelationshipsDialog.hide();"/>
                    </p:dialog>
                </h:form>
                <h:form id="adminPublicRelationshipsForm">
                    <p:growl id="preferencesGrowl" showDetail="false" life="4000"/>
                    <p:toolbar id="tb">  
                        <p:toolbarGroup align="left">  
                            <p:commandButton value="#{messages.NewPublicRelationships}" update=":newPublicRelationshipsDialogForm:newPublicRelationshipsDialogPanel" oncomplete="newPublicRelationshipsDialog.show();" id="newPublicRelationshipsButton" />
                            <p:commandButton id="viewProfileButton" disabled="#{adminPublicRelationshipsBean.chosenEntity==null}" value="#{messages.EditProfile}" update=":publicRelationsEditForm:publicRelationsEditPanel publicRelationsDataTable" onsuccess="editProfileDialog.show()"/>  
                            <p:commandButton id="removeProfileButton" disabled="#{adminPublicRelationshipsBean.chosenEntity==null}" value="#{messages.RemoveProfile}" onclick="removePublicRelationsDialog.show()" update="publicRelationsDataTable"> 
                            </p:commandButton>
                        </p:toolbarGroup>  
                    </p:toolbar> 
                    <p:panel id="publicRelationsDataTable" styleClass="noBorder noPadding noMargin">
                        <p:dataTable var="rrpp" value="#{adminPublicRelationshipsBean.entityList}" rowKey="#{rrpp.idPublicRelationships}" selection="#{adminPublicRelationshipsBean.chosenEntity}" selectionMode="single" filteredValue="#{adminPublicRelationshipsBean.filteredEntitiesList}"
                                     paginator="true" rows="25"  
                                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="25,50,100">    
                            <p:ajax event="rowSelect" update=":adminPublicRelationshipsForm:tb "/>
                            <p:ajax event="rowUnselect" update=":adminPublicRelationshipsForm:tb"/>
                            <p:column filterBy="#{rrpp.name}" filterMatchMode="contains" sortBy="#{rrpp.name}" headerText="#{messages.Name}">  
                                <h:outputText value="#{rrpp.name}" />  
                            </p:column>  
                            <p:column filterBy="#{rrpp.lastName}" filterMatchMode="contains" sortBy="#{rrpp.lastName}" headerText="#{messages.LastName}">  
                                <h:outputText value="#{rrpp.lastName}" />  
                            </p:column>
                            <p:column filterBy="#{rrpp.dni}" filterMatchMode="contains" sortBy="#{rrpp.dni}" headerText="#{messages.Dni}">  
                                <h:outputText value="#{rrpp.dni}" />  
                            </p:column>
                            <p:column filterBy="#{rrpp.user.email}" filterMatchMode="contains" sortBy="#{rrpp.user.email}" headerText="#{messages.Email}">  
                                <h:outputText value="#{rrpp.user.email}" />  
                            </p:column>
                            <p:column filterBy="#{rrpp.phone}" filterMatchMode="contains" sortBy="#{rrpp.phone}" headerText="#{messages.Phone}">  
                                <h:outputText value="#{rrpp.phone}" />  
                            </p:column> 
                            <p:column sortBy="#{rrpp.payPerCandidate}" headerText="#{messages.PayPerCandidate}">  
                                <h:outputText value="#{rrpp.payPerCandidate}" />  
                            </p:column>  
                            <p:column sortBy="#{rrpp.referals}" headerText="#{messages.Referals}">  
                                <h:outputText value="#{rrpp.referals}" />  
                            </p:column>  
                            <p:column filterOptions="#{adminPublicRelationshipsBean.trueFalseOptions}"  
                                      filterMatchMode="exact" filterBy="#{rrpp.user.active}" sortBy="#{rrpp.user.active}" headerText="#{messages.Active}">  
                                <h:outputText value="#{messages.Yes}" rendered="#{rrpp.user.active}" />  
                                <h:outputText value="#{messages.No}" rendered="#{!rrpp.user.active}" /> 
                            </p:column>                  
                        </p:dataTable>  
                    </p:panel>
                    <p:dialog modal="true" style="width:250px;" header="#{messages.AreYouSure}" resizable="false" id="removePublicRelationsDialog" widgetVar="removePublicRelationsDialog"  draggable="true" closable="true">  
                        <p:commandButton process="@this" value="#{messages.No}" onsuccess="removePublicRelationsDialog.hide();" update="removePublicRelationsDialog"/>  
                        <p:commandButton process="@parent" value="#{messages.Yes}" actionListener="#{adminPublicRelationshipsBean.removeProfile()}" onsuccess="removePublicRelationsDialog.hide();" update="publicRelationsDataTable removePublicRelationsDialog"/> 
                    </p:dialog> 
                </h:form>

            </ui:define>
        </ui:composition>

    </body>
</html>
